<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>

 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px)
        {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $('#backid').click(function(){
                window.location.href="index.html";
            });
            //获取id
            let uId = window.location.href.split("?")[1].split("=")[1];
            $.ajax({
                url: "http://localhost:8080/user/selectUserById",
                data: {
                    'i': uId,
                },
                type: 'POST',
                dataType: 'json',
                success: function (response) {

                    let user = response.data.user;

                    $("input[name='uLoginname']").val(user.uLoginname);
                    $("input[name='password']").val(user.uPassword);
                    $("input[name='realname']").val(user.uTruename);
                    $("input[name='email']").val(user.uEmail);
                   // var status = $(".sex").val();
                   // $(":radio[name='sex'][value='" + sex + "']").prop("checked", "checked");

                    //$("input[name='role']").val(user.role.rName);
                    $("input[name='status'][value='user.uState']").attr("checked",true); //根据Value值设置Radio为选中状态

                }
            })
        });
        function genxin(){
            var userName = $("input[name='username']").val();
            var passWord = $("input[name='password']").val();
            var trueName = $("input[name='realname']").val();
            var email = $("input[name='email']").val();
            var ustate = $("input[name='status']:checked").val();
            //var roleId = $("#roleid").val();
            var role=$('#roleid option:selected');
            var rd=role.val()
            var regex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}');
            if (passWord == null || passWord == '') {
                alert("密码为空");
                return;
            } else {
                regex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}');
                if (!regex.test(passWord)) {
                    alert("密码中必须包含字母、数字、特称字符，至少8个字符，最多30个字符");
                    return;
                }
            }
            if (email == null || email == '') {
                alert("邮箱为空");
                return;
            } else {
                let regex = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
                if (!regex.test(email)) {
                    alert("邮箱格式不正确!");
                    return;
                }
            }

            initData(userName,passWord,trueName,email,ustate,rd);
        }

        function initData(username,password,realname,email,status,rd) {
            $.ajax({
                url: "http://localhost:8080/user/updateUser",
                data: {
                    'userName': username,
                    'passWord': password,
                    'trueName': realname,
                    'email': email,
                    'state': status,
                    'roleId': rd,
                },
                type: 'POST',
                dataType: 'json',
                success: function (resp) {
                    if (resp.response.flag) {
                        window.location.href = "index.html";
                    }
                }
            })
        }


    </script>



</head>
<body>
<form action="#" method="post" class="definewidth m20">
<input type="hidden" name="id" value="{$user.id}" />
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">登录名</td>
            <td><input type="uLoginname" name="uLoginname" readonly="readonly" ></td>
        </tr>
        <tr>
            <td class="tableleft">密码</td>
            <td><input type="password" name="password" /></td>
        </tr>
        <tr>
            <td class="tableleft">真实姓名</td>
            <td><input type="text" name="realname"  readonly="readonly" value="admin"/></td>
        </tr>
        <tr>
            <td class="tableleft">邮箱</td>
            <td><input type="text" name="email" value="qq@qq.com"/></td>
        </tr>
        <tr>
            <td class="tableleft">状态</td>
            <td>
                <input type="radio" name="status" value="0" checked/> 启用
              <input type="radio" name="status" value="1" /> 禁用
            </td>
        </tr>
        <tr>
            <td class="tableleft">角色</td>
            <td>
            	<select name="role" id="roleid">
        			<option value="0" >--请选择--
        			<option value="1" >管理员
        			<option value="2">院长
            		<option value="3">医生护士
       			 </select>
        	</td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <input class="btn btn-primary" type="button" value="更新"onclick="genxin()"/>&nbsp;&nbsp;<button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
